﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FF.Entity;
using System.Data.SQLite;
using System.Windows.Forms;

namespace FF.Method
{
    class UserTypeMethod
    {
        public const string TYPE_ADMIN = "A";
        public static int addUserType(UserType userType)
        {
            string sql = "insert into ff_user_type values('";
            sql += userType.type + "','";
            sql += userType.name + "','";
            sql += userType.remark + "')";
            return SQLiteHelper.ExecuteSql(sql);
        }
        public static UserType getUserTypeByTypeCode(string typeCode)
        {
            UserType userType = null;
            try
            {
                SQLiteDataReader reader = SQLiteHelper.ExecuteReader("select * from ff_user_type where type='" + typeCode + "'");
                if (reader.HasRows)
                {
                    reader.Read();
                    userType = new UserType();
                    userType.type = reader.GetString(0);
                    userType.name = reader.GetString(1);
                    userType.remark = reader.GetString(2);
                }
                reader.Close();
                return userType;
            }
            catch (Exception ex)
            {
                MessageBox.Show("程序出错了！" + ex.Message, "提示信息 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }
        public static int updateUserType(UserType ut)
        {
            string sql = "update ff_user_type set ";
            //sql += "user_id='"+user.UserId;
            sql += "name='" + ut.name;
            sql += "',remark='" + ut.remark;
            sql += "' where type='" + ut.type + "'";
            return SQLiteHelper.ExecuteSql(sql);
        }
        public static int deleteUserType(string type)
        {
            if(type.Equals(TYPE_ADMIN))
            {
                MessageBox.Show("不能删除这种用户类型！");
            }
            string sql = "delete from ff_user_type where type='" + type + "'";
            return SQLiteHelper.ExecuteSql(sql);
        }
    }
}
